<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>OpenShoe: sleepmgr.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenShoe
   &#160;<span id="projectnumber">0.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">sleepmgr.h</div>  </div>
</div>
<div class="contents">
<a href="uc3_2sleepmgr_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00038"></a>00038 <span class="preprocessor">#ifndef UC3_SLEEPMGR_H</span>
<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor">#define UC3_SLEEPMGR_H</span>
<a name="l00040"></a>00040 <span class="preprocessor"></span>
<a name="l00041"></a>00041 <span class="preprocessor">#ifdef __cplusplus</span>
<a name="l00042"></a>00042 <span class="preprocessor"></span><span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span> {
<a name="l00043"></a>00043 <span class="preprocessor">#endif</span>
<a name="l00044"></a>00044 <span class="preprocessor"></span>
<a name="l00045"></a>00045 <span class="preprocessor">#include &lt;<a class="code" href="compiler_8h.html" title="Compiler file for AVR32.">compiler.h</a>&gt;</span>
<a name="l00046"></a>00046 <span class="preprocessor">#include &lt;<a class="code" href="conf__sleepmgr_8h.html" title="Chip-specific sleep manager configuration.">conf_sleepmgr.h</a>&gt;</span>
<a name="l00047"></a>00047 <span class="preprocessor">#include &lt;<a class="code" href="sleep_8h.html" title="Sleep mode access.">sleep.h</a>&gt;</span>
<a name="l00048"></a>00048 
<a name="l00054"></a><a class="code" href="group__sleepmgr__group.html#gaa990bc3ea16fcad09009cdc70dbc38c6">00054</a> <span class="keyword">enum</span> <a class="code" href="group__sleepmgr__group.html#gaa990bc3ea16fcad09009cdc70dbc38c6" title="Sleep mode locks.">sleepmgr_mode</a> {
<a name="l00056"></a><a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6a04a2ceb6fc138cae84e9334cfa90d89f">00056</a>         <a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6a04a2ceb6fc138cae84e9334cfa90d89f" title="Active mode.">SLEEPMGR_ACTIVE</a>,
<a name="l00058"></a><a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6ae4f3742b3532d5ebabef6f26fabf4487">00058</a>         <a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6ae4f3742b3532d5ebabef6f26fabf4487" title="Idle mode.">SLEEPMGR_IDLE</a>,
<a name="l00060"></a><a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6a07fe232646cccb4c2b9e0ba301866cb9">00060</a>         <a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6a07fe232646cccb4c2b9e0ba301866cb9" title="Frozen mode.">SLEEPMGR_FROZEN</a>,
<a name="l00062"></a><a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6affb1e224bd127ccf5c7b54a54c3ba665">00062</a>         <a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6affb1e224bd127ccf5c7b54a54c3ba665" title="Standby mode.">SLEEPMGR_STDBY</a>,
<a name="l00064"></a><a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6a84505afbeafb45b0c9e9b5fc1a1e3e5e">00064</a>         <a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6a84505afbeafb45b0c9e9b5fc1a1e3e5e" title="Stop mode.">SLEEPMGR_STOP</a>,
<a name="l00066"></a><a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6a6ee894e3a9dc55e678d10a9cebff5dd1">00066</a>         <a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6a6ee894e3a9dc55e678d10a9cebff5dd1" title="Deep Stop mode.">SLEEPMGR_DEEPSTOP</a>,
<a name="l00068"></a><a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6adbc00d523bb40feb59822bfbec8106c4">00068</a>         <a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6adbc00d523bb40feb59822bfbec8106c4" title="Static mode.">SLEEPMGR_STATIC</a>,
<a name="l00069"></a>00069 <span class="preprocessor">#if UC3L</span>
<a name="l00070"></a>00070 <span class="preprocessor"></span>
<a name="l00071"></a>00071         SLEEPMGR_SHUTDOWN,
<a name="l00072"></a>00072 <span class="preprocessor">#endif</span>
<a name="l00073"></a><a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6a02fd0aaf6162fa103be2aa0b2593a984">00073</a> <span class="preprocessor"></span>        <a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6a02fd0aaf6162fa103be2aa0b2593a984">SLEEPMGR_NR_OF_MODES</a>,
<a name="l00074"></a>00074 };
<a name="l00075"></a>00075 
<a name="l00081"></a>00081 <span class="preprocessor">#if defined(CONFIG_SLEEPMGR_ENABLE) || defined(__DOXYGEN__)</span>
<a name="l00082"></a>00082 <span class="preprocessor"></span>
<a name="l00083"></a>00083 <span class="keyword">extern</span> uint8_t sleepmgr_locks[];
<a name="l00084"></a>00084 <span class="preprocessor">#endif </span><span class="comment">/* CONFIG_SLEEPMGR_ENABLE */</span>
<a name="l00085"></a>00085 
<a name="l00086"></a>00086 
<a name="l00087"></a>00087 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> sleepmgr_enter_sleep(<span class="keywordtype">void</span>)
<a name="l00088"></a>00088 {
<a name="l00089"></a>00089 <span class="preprocessor">#ifdef CONFIG_SLEEPMGR_ENABLE</span>
<a name="l00090"></a>00090 <span class="preprocessor"></span>        <span class="keywordtype">int</span>                   sleep_mode = -1; <span class="comment">// -1 representing the ACTIVE mode</span>
<a name="l00091"></a>00091         uint8_t               *lock_ptr = sleepmgr_locks;
<a name="l00092"></a>00092 
<a name="l00093"></a>00093         cpu_irq_disable();
<a name="l00094"></a>00094 
<a name="l00095"></a>00095         <span class="comment">// Find first non-zero lock count, starting with the shallowest modes.</span>
<a name="l00096"></a>00096         <span class="keywordflow">while</span>(!(*lock_ptr++)) {
<a name="l00097"></a>00097                 sleep_mode++;
<a name="l00098"></a>00098         }
<a name="l00099"></a>00099         <span class="comment">// Catch the case where one too many sleepmgr_unlock_mode() call has been</span>
<a name="l00100"></a>00100         <span class="comment">// performed on the deepest sleep mode.</span>
<a name="l00101"></a>00101         Assert((uintptr_t)(lock_ptr - sleepmgr_locks) &lt; <a class="code" href="group__sleepmgr__group.html#ggaa990bc3ea16fcad09009cdc70dbc38c6a02fd0aaf6162fa103be2aa0b2593a984">SLEEPMGR_NR_OF_MODES</a>);
<a name="l00102"></a>00102 
<a name="l00103"></a>00103         <span class="keywordflow">if</span>(sleep_mode &gt;= AVR32_PM_SMODE_IDLE) {
<a name="l00104"></a>00104                 <span class="comment">// Atomically enable the global interrupts and enter the sleep mode.</span>
<a name="l00105"></a>00105                 pm_sleep(<a class="code" href="sleep_8h.html#ae3781b77d6e4988416907e70d197616b">AVR32_PM_SMODE_GMCLEAR_MASK</a> | sleep_mode);
<a name="l00106"></a>00106         }
<a name="l00107"></a>00107         <span class="keywordflow">else</span> {
<a name="l00108"></a>00108                 <span class="comment">// Case where the ACTIVE mode is locked (i.e. no sleep mode allowed).</span>
<a name="l00109"></a>00109                 <span class="comment">// Enable the interrupts to have the same behavior in all cases.</span>
<a name="l00110"></a>00110                 cpu_irq_enable();
<a name="l00111"></a>00111         }
<a name="l00112"></a>00112 <span class="preprocessor">#else</span>
<a name="l00113"></a>00113 <span class="preprocessor"></span>        cpu_irq_enable();
<a name="l00114"></a>00114 <span class="preprocessor">#endif </span><span class="comment">/* CONFIG_SLEEPMGR_ENABLE */</span>
<a name="l00115"></a>00115 }
<a name="l00116"></a>00116 
<a name="l00118"></a>00118 
<a name="l00119"></a>00119 <span class="preprocessor">#ifdef __cplusplus</span>
<a name="l00120"></a>00120 <span class="preprocessor"></span>}
<a name="l00121"></a>00121 <span class="preprocessor">#endif</span>
<a name="l00122"></a>00122 <span class="preprocessor"></span>
<a name="l00123"></a>00123 <span class="preprocessor">#endif </span><span class="comment">/* UC3_SLEEPMGR_H */</span>
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Mon Dec 19 2011 21:04:51 for OpenShoe by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
